﻿#include "common.h"

#include <QtMath>
#include <cmath>

/**
 * @brief calculateDistanceOptimized
 * @param point1
 * @param point2
 * @return
 */
double calculateDistanceOptimized(const QPoint &point1,const QPoint &point2)
{
    double dx = point2.x() - point1.x();
    double dy = point2.y() - point1.y();

    return std::sqrt(dx * dx + dy * dy);
}

/**
 * @brief calculateNewPoint
 * @param pointA
 * @param length
 * @param angleDegrees
 * @return
 */
QPoint calculateNewPoint(const QPoint &pointA, double length, double angleDegrees)
{
    // 将角度从度转换为弧度（如果需要的话）
    double angleRadians = qDegreesToRadians(angleDegrees);

    // 使用极坐标到直角坐标的转换公式
    int xB = pointA.x() + static_cast<int>(length * std::cos(angleRadians));
    int yB = pointA.y() + static_cast<int>(length * std::sin(angleRadians));

    return QPoint(xB, yB);
}
